**************************************************************************************************************
**	Replication do-file for "Social Democracy and the Birth of Working-Class Representation in Europe"
**  Purpose: Replicate Figures 1&2 for Germany (both pre-war and interwar)
*************************************************************************************************************

set more off
/* set the directory */

/**************************
FIGURE 1 Imperial Germany
***************************/

use "Germany prewar.dta", clear

**		calculate the total number of MPs per year
egen total_mps=count(id_bio), by(rt_year)
label var rt_year "Year"

**		calculate the total number of working-class MPs per year
foreach occ of varlist mp_manual {		 
					   egen total_`occ'=total(`occ'), by(rt_year)					 
					   gen `occ'_pct=(total_`occ'/total_mps)*100	 
}

**  Add the SPD's seat share
egen total_spd_win =count(id_bio) if spd==1, by(rt_year)
gen spd_share=(total_spd_win/total_mps)*100

rename rt_year year
keep year mp_manual_pct spd_share
duplicates drop year mp_manual_pct spd_share, force
save "Germany Imperial over time.dta", replace

/**************************
FIGURE 1  Weimar Republic
***************************/
use "Germany interwar.dta", clear
gen spd=(party==100)
rename lp year
recode year (17=1920) (19=1924) (20=1928) (21=1930)


**		calculate the total number of MPs per year
egen total_mps=count(id_weimar), by(year)

**		calculate the total number of working-class MPs per year
foreach occ of varlist mp_manual {		 
					   egen total_`occ'=total(`occ'), by(year)					 
					   gen `occ'_pct=(total_`occ'/total_mps)*100		 
}

**  Add the SPD's seat share
gen spd_share=.
replace spd_share=0 if year >1912 & year<1920
replace spd_share=(103/459)*100 if year==1920
replace spd_share=(131/493)*100 if year==1924
replace spd_share=(153/491)*100 if year==1928
replace spd_share=(143/577)*100  if year==1930

keep year mp_manual_pct spd_share
duplicates drop year mp_manual_pct spd_share, force
save "Germany Weimar over time.dta", replace

/***************************************
Now append the Imperial Germany data
****************************************/
append using "Germany Imperial over time.dta"
label var year "Year"
sort year
twoway (area spd_share year if year<1918, lc(gs12) fc(gs12)) ///
(area spd_share year if year>1912, lc(gs12) fc(gs12)) ///
(connect mp_manual_pct year if year<1918, lc(gs5) m(i) lw(.7)) ///
(connect mp_manual_pct year if year>1918  & year<=1930, lc(gs5) m(i) lw(.7)) ///
(connect mp_manual_pct year if year>=1912 & year<=1920, lc(gs5) lp(dot) m(i)  lw(.7)), ///
xlabel(1871 1874 1877 1878 1881 1884 1887 1890 1893 1898 1903 1908 1912 1920 1924 1928 1930 ///
, labsize(6) alt)  ///
ylabel(0(10)40, labsize(5.5)) xtitle(, size(7)) title("Germany", size(8)) name(mps_empire, replace) xsize(12) /// 
ytitle("Percent Workers", size(7)) graphregion(color(white)) ///
 legend (order(1 "SPD Seat Share" 4 "Worker") row(1)) 
*save "paper drafts\figures\Germany_over_time.gph", replace
*graph export "paper drafts\figures\Germany_over_time.png", replace  
	  
/********************************************
     Figure 2: Percentages for the Tree Map
*********************************************/
use "Germany prewar.dta", clear /*ERROR*/
ta pty mp_manual 
di 93/110 /* socialist working-class MPs */
di 14/110 /* zentrum working-class MPs */

use "Germany interwar.dta", clear
ta party mp_manual 
di 415/738  /* socialist working-class MPs */
di 92/738   /* zentrum working-class MPs */
di 112/738  /* communist */
di 119/738   /* rest */

